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uk5HQUxHT1RSQURFUgAVAAAAWkhBTkdaSDpSTkdC
T05EVFJBREVSABMAAABaSEFOR1pIOlJOR01NVVNBTEVTABMAAABaSEFOR1pIOlJOR01NVVNUUkFUABUA
AABaSEFOR1pIOlJOR1NXQVBUUkFERVIADgAAAFpIQU5HWkg6U1NURVNUAA8AAABaSEFOR1pIOlNUUkVB
TTMADwAAAFpIQU5HWkg6U1VQUE9SVAAUAAAAWkhBTkdaSDpUUkFERUFDQ09VTlQACwAAAFpIQU5HWkg6
VklEAA4AAABaSEFOR1pIOlpIVUFORwAOAAAAWkhBTkdaSDp0cmFkZXIADgAAAFpIQU5HWkg6dmlld2Vy
ABIAAABaSEFOR1pIOnZpcnR1YWxJRDEABAAAAElERUEA
-----END PILOT AUTHENTICATION ASSERTION-----`;


//window.processConfig = cp.processConfig.bind(cp);
//cp.processConfig(config2);


// testSampledData();



window.timers = [];

// testTickData();
newConfig.payload.requestId = newConfig.requestId;
testTickData(newConfig.requestId);
// var param = getParameterByName("type");
// if(param == "tick"){
// }else{
    // }
// testOHLCData("f5.c1.p",newConfig.requestId);



function testTickData(requestId){
    t_sendNewChartConfig();
    window.subscription = cv.sendConfig(newConfig.payload);
    t_sendNewStart(requestId);
    t_sendNewQueryTick(requestId);
    t_sendError(requestId);
    t_sendNewEnd(requestId);
    var timer1 = setInterval(t_sendNewTick.bind(this,"f5.c1.p",requestId),3000);
    var timer2 = setInterval(t_sendNewTick.bind(this,"f10.c2.p",requestId),3000);
    window.timers.push(...[timer1,timer2]);
}



function testOHLCData(seriesName,requestId){
    newConfig.payload.dataOptions.sampleInterval = 60*1000;
    t_sendNewChartConfig();
    window.subscription = cv.sendConfig(newConfig.payload);
    t_sendNewStart(requestId);
    t_sendSampleHistOHLCData(seriesName,requestId);
    t_sendNewEnd(requestId);
    var timer = setInterval(t_sendOHLCSubData.bind(this,seriesName,requestId),3000);
    window.timers.push(timer);
}

// window.oncontextmenu = function(e){
//     //console.log("oncontextmenu",e);

//     return false;
// }

var el = document.getElementById("select_dataInterval");
el.addEventListener("change",function(event){
    var interval = parseInt(el.value);
    var requestId = "abcd"
    pilotChart.clearAllSeries();
    cv.seriesData = {};
    cv.changeDataInterval(interval,300,requestId);
    // window.timers.forEach(timer => {
    //     clearInterval( window.timer);
    // });
    // window.timers = [];
    if(window.subscription){
        window.subscription.unsubscribe();
    }
    setTimeout(() => {  
        t_sendNewStart(requestId);
        t_sendSampleHistOHLCData("f5.c10.p",requestId);
        t_sendNewEnd(requestId);
        var timer = setInterval(t_sendOHLCSubData.bind(this,"f5.c10.p",requestId),3000);
        window.timers.push(timer);
    }, 5000);
})

var els = document.getElementsByClassName("range-selector")[0].firstElementChild;
els.addEventListener("click",function(){
    var requestId = "eabc";
    t_sendNewStart(requestId)
    t_sendMoreSampleHistOHLCData("f5.c1.p",requestId);
    t_sendNewEnd(requestId)
})

// window.addEventListener( "menuEvent", function( event ) {
//     console.log("menuEvent",event);
// })